/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.mine.presenter;

import com.yiqi.lottery.entity.bo.BalanceBo;
import com.yiqi.lottery.entity.bo.OrderDetailBo;
import com.yiqi.lottery.feature.mine.contract.BanlanceContract;
import com.yiqi.lottery.feature.mine.contract.DetailContract;
import com.yiqi.lottery.feature.mine.dependencies.banlance.DaggerBanlancePresenterComponent;
import com.yiqi.lottery.feature.mine.dependencies.detail.DaggerDetailPresenterComponent;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class DetailPresenter implements DetailContract.Presenter {

    private DetailContract.View mView;

    @Inject

    DetailContract.Model mModel;


    public DetailPresenter(DetailContract.View mView) {
        this.mView = mView;
        DaggerDetailPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getOrderDetail(int order_id,int type) {
        mModel.getOrderDetail(order_id,type).compose(mView.bindToLife()).subscribe(new Observer<OrderDetailBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(OrderDetailBo detailBo) {
                mView.showOrderDetailSuccess(detailBo);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showOrderDetailError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getCopurceDetail(int order_id) {
        mModel.getCopurceDetail(order_id).compose(mView.bindToLife()).subscribe(new Observer<OrderDetailBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(OrderDetailBo detailBo) {
                mView.showOrderDetailSuccess(detailBo);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showOrderDetailError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
